def test_raise():
    try:
        raise ValueError("ValueError")
    except Exception as exc:
        raise RuntimeError("RuntimeError")


def test_raise_from():
    try:
        raise ValueError("ValueError")
    except Exception as exc:
        raise RuntimeError("RuntimeError") from exc


def test_raise_from_none():
    try:
        raise ValueError("ValueError")
    except Exception as exc:
        raise RuntimeError("RuntimeError") from None  # from None 会输出禁止上下文


class CustomException(Exception):
    def __init__(self, err_msg='这是自定义异常'):
        super().__init__(err_msg)


def test_custom_exception():
    raise CustomException()


if __name__ == '__main__':
    # raise ValueError('ValueError')
    # test_raise()
    # test_raise_from()
    # test_raise_from_none()

    test_custom_exception()
